using RAG.Domain.Services;

namespace RAG.Application.Services;

/// <summary>
/// 文档应用服务接口 - 应用层
/// </summary>
public interface IDocumentApplicationService
{
    // 上传文件并创建文档记录
    Task<UploadFilesResponse> UploadFilesAsync(UploadFilesRequest request, Guid userId);
    
    // 获取文档列表（分页）
    Task<DocumentListResponse> GetDocumentsAsync(int page = 1, int pageSize = 20, string? keyword = null, string? accessLevel = null);
    
    // 获取单个文档
    Task<DocumentInfo?> GetDocumentByIdAsync(Guid id);
    
    // 更新文档信息
    Task<DocumentInfo?> UpdateDocumentAsync(Guid id, DocumentUpdateRequest updateRequest);
    
    // 删除文档
    Task<bool> DeleteDocumentAsync(Guid id);
    
    // 批量删除文档
    Task<bool> DeleteDocumentsAsync(List<Guid> ids);
    
    // 获取文档统计信息
    Task<DocumentStatisticsResponse> GetDocumentStatisticsAsync();
}

// 应用层的DTO
public class DocumentInfo
{
    public string? Id { get; set; }
    public string Title { get; set; } = default!;
    public string? Description { get; set; }
    public string? Tags { get; set; }
    public string AccessLevel { get; set; } = "Internal";
    public string? FileName { get; set; }
    public string? FilePath { get; set; }
    public string? FileType { get; set; }
    public string? FileSize { get; set; }
    public string Status { get; set; } = "Pending";
    public DateTime? CreatedAt { get; set; }
    public DateTime? UpdatedAt { get; set; }
    public string? UserId { get; set; }
    public string? UserName { get; set; }
}

public class UploadFilesRequest
{
    public List<RAG.Domain.Services.FileInfo> Files { get; set; } = new();
    public string? Description { get; set; }
    public string? Tags { get; set; }
    public string AccessLevel { get; set; } = "Internal";
}

public class UploadFilesResponse
{
    public List<DocumentInfo> SuccessDocuments { get; set; } = new();
    public List<UploadError> FailedFiles { get; set; } = new();
    public int TotalCount { get; set; }
    public int SuccessCount { get; set; }
    public int FailedCount { get; set; }
}

public class DocumentListResponse
{
    public List<DocumentInfo> Documents { get; set; } = new();
    public int TotalCount { get; set; }
    public int Page { get; set; }
    public int PageSize { get; set; }
    public int TotalPages { get; set; }
}

public class DocumentUpdateRequest
{
    public string Title { get; set; } = default!;
    public string? Description { get; set; }
    public string? Tags { get; set; }
    public string AccessLevel { get; set; } = "Internal";
}

public class DocumentStatisticsResponse
{
    public int TotalDocuments { get; set; }
    public int PendingDocuments { get; set; }
    public int ProcessingDocuments { get; set; }
    public int CompletedDocuments { get; set; }
    public int FailedDocuments { get; set; }
    public long TotalFileSize { get; set; }
}

public class UploadError
{
    public string FileName { get; set; } = default!;
    public string Error { get; set; } = default!;
} 